# 已知身份证号
id_card = "110101199003074512"

# 1. 提取前6位地址码
address_code = id_card[:6]
print("地址码:", address_code)

# 地址码映射表（示例：仅包含题目中地址码对应的地区，实际需更完整的映射）
address_map = {
    "110000": "北京市",
    "110100": "北京市市辖区",
    "110101": "北京市东城区",
    # 可根据需要扩展更多地址码...
}

# 根据地址码获取现实地址
def get_address(code):
    # 优先匹配6位完整地址码
    if code in address_map:
        return address_map[code]
    # 匹配前4位（市级别）
    elif code[:4] + "00" in address_map:
        return address_map[code[:4] + "00"]
    # 匹配前2位（省级别）
    elif code[:2] + "0000" in address_map:
        return address_map[code[:2] + "0000"]
    else:
        return "未知地区"

real_address = get_address(address_code)
print("现实地址:", real_address)

# 2. 提取出生年（两种索引方式）
birth_year1 = id_card[6:10]  # 正索引
birth_year2 = id_card[-12:-8]  # 负索引
print("出生年（正索引）:", birth_year1)
print("出生年（负索引）:", birth_year2)

# 3. 提取出生月和出生日并格式化输出
birth_month = id_card[10:12]
birth_day = id_card[12:14]
print(f"出生年月：{birth_year1} 年 {birth_month} 月 {birth_day} 日")

# 4. 获取性别信息
gender_code = id_card[16]
gender = "男" if int(gender_code) % 2 == 1 else "女"
print("性别:", gender)